<template>
  <div>
    <div class="top-info">
      <div class="user">欢迎您！{{ username }}</div>
      <div class="person">
        <li>
          <a href="javascript:;" @click="psersonTo">个人资料</a>
        </li>
        <li>
          <a href="javascript:;" @click="loginOut">退出登录</a>
        </li>
      </div>
    </div>
    <div class="titile-img">
      <img src="@/assets/image/3.jpg" alt="个人图书共享系统" />
      <div class="title-com">
        <span>个人图书共享系统</span>
      </div>
    </div>
    <!-- 导航条 -->
    <div class="nav">
      <li v-for="(item, index) in pageLists" :key="index">
        <a href="javascript:;" @click="routeTo(item.path)">{{ item.name }}</a>
      </li>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Header',
  components: {},
  data() {
    return {
      username: '',
      pageLists: [
        { name: '首页', id: '0', path: '/home' },
        { name: '共享书籍', id: '2', path: '/uploadlist' },
        { name: '我的书籍', id: '3', path: '/sharebook' },
        { name: '我要留言', id: '4', path: '/leavemessage' },
        { name: '通知公告', id: '5', path: '/announce' },
        { name: '查看反馈', id: '6', path: '/feedback' }
      ]
    };
  },
  mounted() {
    this.username = localStorage.getItem('username');
  },
  methods: {
    OtherPage() {},
    routeTo: function(path) {
      this.$router.push(path);
    },
    psersonTo() {
      this.$router.push('/personinfo');
    },
    upDatePass() {
      this.$router.push('/modifypassword');
    },
    loginOut() {
      // 退出
      localStorage.removeItem('username');
      localStorage.removeItem('userId');
      this.$router.push('/main');
    }
  }
};
</script>

<style lang="less" scoped>
.top-info {
  position: relative;
  height: 50px;
  width: 100%;
  background-color: #016db5;
  img {
    width: 50px;
    border-radius: 25%;
    height: 40px;
  }
  .user {
    position: absolute;
    right: 220px;
    top: 10px;
    display: inline-block;
    color: white;
    font-weight: 800;
    font-size: 20px;
  }
  span {
    display: inline-block;
    margin: 0 10px;
    font-size: 20px;
    font-weight: bold;
    color: white;
  }
  .person {
    position: absolute;
    right: 0;
    width: auto;
    vertical-align: middle;
    li {
      width: 100px;
      height: 50px;
      line-height: 50px;
      float: left;
      a {
        display: inline-block;
        width: 100%;
        color: white;

        &:hover {
          color: red;
        }
      }
    }
  }
}
.titile-img {
  position: relative;
  height: 200px;
  width: 100%;
  img {
    width: 100%;
    height: 200px;
  }
  .title-com {
    position: absolute;
    top: 23%;
    left: 37%;
    span {
      font-size: 50px;
      letter-spacing: 10px;
      font-family: '隶书';
      color: #fbf7f9;
      text-shadow: 0px 3px 7px #ffffff;
    }
  }
}
.nav {
  width: 1200px;
  height: 50px;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  background-color: #016db5;
  li {
    width: 100%;
    text-align: center;
    a {
      display: inline-block;
      width: 100%;
      height: 50px;
      line-height: 50px;
      color: white;
      &:hover {
        color: red;
        background-color: #fff;
      }
    }
  }
}
</style>
